#include "enemyplane.h"
#include "base1.h"
#include<QString>
enemyplane::enemyplane()
{
    //敌机资源加载
    n=rand()%4;
    QString str2=QString(ENEMY_PATH1).arg(n);
    m_enemy.load(str2);

    //敌机位置
    m_x=0;
    m_y=0;

    //敌机状态
    m_free=true;

    //敌机速度
    m_speed=ENEMY_SPEED;

    //敌机矩形框，用于碰撞检测
    m_Rect.setWidth(m_enemy.width());
    m_Rect.setHeight(m_enemy.height());
    m_Rect.moveTo(m_x,m_y);
}

void enemyplane::updatePosition()
{
    //空闲状态的敌机不计算坐标
    if(m_free)
    {
       return;
    }

        m_y+=m_speed;
        m_Rect.moveTo(m_x,m_y);
    //如果超出屏幕，空闲状态
        if(m_y>=GAME_HEIGHT+m_Rect.height())
        {
            m_free=true;
        }
}
